//
//  BNHomeDetailListView.m
//  BNCodeGuide
//
//  Created by Mac on 2021/5/22.
//  Copyright © 2021 kevin007. All rights reserved.
//

#import "BNHomeDetailListView.h"

#import "BNHomeDetailTableViewCell.h"   //cell
#import "BNHomeDetailSectionHeaderView.h" //seation header

@implementation BNHomeDetailListView
- (instancetype)initWithFrame:(CGRect)frame tableViewStyle:(UITableViewStyle)style {
    if (self = [super initWithFrame:frame tableViewStyle:style]) {
        self.tableView.contentInset = UIEdgeInsetsMake(20, 0, 20, 0);
    }
    return self;
}

#pragma mark - -------------UICollectionViewDataSource----------------
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.dataSource.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    BNHomeDetailTableViewCell *cell = [BNHomeDetailTableViewCell cellFromClassWithTableView:tableView];
    
    cell.text = self.dataSource[indexPath.row];
    
    NSInteger sectionItemCount = [tableView numberOfRowsInSection:indexPath.section];
    cell.isLastCell = indexPath.row == sectionItemCount - 1;
    return cell;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    BNHomeDetailSectionHeaderView *header = [BNHomeDetailSectionHeaderView headerFooterViewFromXibWithTableView:tableView];
    header.titleLabel.text = [NSString stringWithFormat:@"section-%ld",section];
    
    return header;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 60;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    return [[UIView alloc] init];
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 20.0;
}
@end
